package com.java.mybatis.controller;

import com.java.mybatis.entity.Car;
import com.java.mybatis.service.CarService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (Car)表控制层
 *
 * @author makejava
 * @since 2021-01-15 17:10:28
 */
@Controller
@RequestMapping("/car/")
public class CarController {
    /**
     * 服务对象
     */
    @Resource
    private CarService carService;


    /**
     * 牟恩跃----添加数据
     */

    @RequestMapping("")
    public String Carinsert(Car car){



        return null;
    }
    /**
     * 牟恩跃----模糊查询
     * @return 单条数据
     */
    @RequestMapping("Carlike")
    public String Carlike(String carNumber,Model model){
        System.out.println(carNumber);
        List<Car> carlike = this.carService.Carlike("%"+carNumber+"%");
        System.out.println("数据");
        System.out.println(carlike);
        //返回给页面
        model.addAttribute("car",carlike);
        return "System/sys-shield";
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Car selectOne(Integer id) {
        System.out.println(carService.queryById(1));
        return this.carService.queryById(id);
    }
    @RequestMapping("getQuerySel")
    public String getQuerySel(Model model)
    {
        List<Car> querySel = carService.getQuerySel();
        model.addAttribute("carS",querySel);
        return "System/echart-1";
    }

    /**
     * 查询所有的内容
     * @param car
     * @param model
     * @return
     */
     @RequestMapping("CarselectAll")
     public String CarselectAll(Car car, Model model){
         //把数据存到list集合
         List<Car> cars = this.carService.CarselectAll(car);
         //查询集合的个数
         int size = cars.size();
         model.addAttribute("sie",size);
         //返回给页面
         model.addAttribute("car",cars);
         return "System/sys-shields";
     }

    @RequestMapping("test")
    public String test(){
        System.out.println(carService.queryById(1));
        return "index";
    }

    @RequestMapping("CarByState")
    public void CarByState(HttpSession session, Integer outboundId, String outboundNumber,String outboundMark){
        System.out.println("--------------------");
        List<Car> cars = carService.carByState();
        session.setAttribute("cars",cars);
        session.setAttribute("outboundId",outboundId);
        session.setAttribute("outboundNumber",outboundNumber);
        session.setAttribute("outboundMark",outboundMark);
    }

}